package com.skyjing.rvadapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding


abstract class MultiItemCommonAdapter<T, V : ViewBinding>(
    context: Context, datas: List<T>
) : CommonAdapter<T, V>(context, datas) {

    override fun getItemViewType(position: Int): Int {
        return if (mDatas.isNotEmpty()) getItemType(position, mDatas[position])
        else NO_DATA
    }

    abstract fun getItemType(position: Int, t: T): Int

    abstract fun getLayout(
        viewType: Int
    ): (LayoutInflater , ViewGroup , Boolean) -> V

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        var v = getLayout(viewType)(LayoutInflater.from(mContext) , parent , false)
        return ViewHolder(v, v.root)
    }
}
